package com.zhj.config.thread;

import java.util.concurrent.*;

/**
 * Copyright: Copyright (c) 2020 hantu
 *
 * @ClassName: MyFutureTaskDemo
 * @Description:
 * @version: v1.0.0
 * @author: zhanghaojie
 * @date: 2020/6/4
 */
public class MyFutureTaskDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService poor= Executors.newFixedThreadPool(10);
        Future<String> future = poor.submit(new MyFutureTask());
        if (!future.isDone()){
            System.out.println("执行未完成");
        }
        System.out.println("执行完成 "+future.get());
        System.out.println(future.getClass().getName());
    }


    private void test1() throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask=new FutureTask<String>(new MyFutureTask());
        Thread t1=new Thread(futureTask);
        t1.start();
        if (!futureTask.isDone()){
            System.out.println("线程执行完成返回值为:"+futureTask.get());
        }
        System.out.println("执行结束");
    }
}
